var cmp = new Array();
var total = new Array(0,0,0,0,0,0,0,0,0);
var choix = document;
var emplacement = null;
function chx_change(id)
{
    membre = id.split("_");
    if(cmp[id]=='display')
    {
        cmp[id]='none';
        display_one = 'none';
        display_all = 'table-row';
    }
    else
    {
        cmp[id]='display';
        display_one = 'table-row';
        display_all = 'none';
    }

    //console.info("id : "+ id + " | cmp[id] :"+cmp[id]);

    choix = document.getElementById(id);
    for(row in choix.parentNode.rows)
    {
        if(choix.parentNode.rows[row].id != undefined)
        {
            emplacement = choix.parentNode.rows[row].id.split("_");
            if(( emplacement[0] == membre[0] && emplacement[0] != "bras")||( emplacement[0]+emplacement[1] == membre[0]+membre[1] && emplacement[0] == "bras"))
                choix.parentNode.rows[row].style.display = display_all;
        }
    }

    switch(cmp[id])
    {
        case 'display':
            total[0] = total[0] + parseInt(choix.childNodes[3].textContent);
            total[1] = total[1] + parseInt(choix.childNodes[4].textContent);
            total[2] = total[2] + parseInt(choix.childNodes[5].textContent);
            total[3] = total[3] + parseInt(choix.childNodes[6].textContent);
            total[4] = total[4] + parseInt(choix.childNodes[7].textContent);
            total[5] = total[5] + parseInt(choix.childNodes[8].textContent);
            total[6] = total[6] + parseInt(choix.childNodes[9].textContent);
            total[7] = parseInt(total[7]*10) + parseInt(choix.childNodes[10].textContent*10);
            total[7] = total[7]/10;
            choix.style.display = display_one;
            break;
        default:
            total[0] = total[0] - parseInt(choix.childNodes[3].textContent);
            total[1] = total[1] - parseInt(choix.childNodes[4].textContent);
            total[2] = total[2] - parseInt(choix.childNodes[5].textContent);
            total[3] = total[3] - parseInt(choix.childNodes[6].textContent);
            total[4] = total[4] - parseInt(choix.childNodes[7].textContent);
            total[5] = total[5] - parseInt(choix.childNodes[8].textContent);
            total[6] = total[6] - parseInt(choix.childNodes[9].textContent);
            total[7] = parseInt(total[7]*10) - parseInt(choix.childNodes[10].textContent*10);
            total[7] = total[7]/10;
            break;
    }
    total_display = document.getElementById("total");
    total_display.childNodes[1].textContent = total[0].toString();

    for(var nb_col = 2;nb_col<=8;nb_col++)
    {
        total_display.childNodes[nb_col].textContent = total[nb_col-1].toString();
        if(total[nb_col-1]==0)
        {
            total_display.childNodes[nb_col].style.backgroundColor = 'inherit';
            total_display.childNodes[nb_col].style.color = 'inherit';
        }
        else if((total[nb_col-1].toString()!="" && nb_col-1!=7 && nb_col-1!=3))
        {
            if(total[nb_col-1]>0)
            {
                total_display.childNodes[nb_col].style.backgroundColor = 'green';
            }
            else if(total[nb_col-1]<0)
            {
                total_display.childNodes[nb_col].style.backgroundColor = 'red';
            }
            total_display.childNodes[nb_col].style.color = 'white';
        }
        else if (nb_col-1==7 || nb_col-1==3)
        {
            if(total[nb_col-1]>0)
            {
                total_display.childNodes[nb_col].style.backgroundColor = 'red';
            }
            else if(total[nb_col-1]<0)
            {
                total_display.childNodes[nb_col].style.backgroundColor = 'green';
            }
            total_display.childNodes[nb_col].style.color = 'white';
        }
    }
}